using System;
using System.Collections;
using System.Collections.Generic;

namespace OffsetPath
{
    public class ClassAa_OssaSkeletro
    {
        private ClassAr a;
        private ClassL aa;
        private ClassAa_OssaSkeletro ab;
        private List<ClassL> ac;
        private ClassAa_OssaSkeletro b;
        private ClassAa_OssaSkeletro c;
        internal PuntoDueD d;
        private SkeletroBaseLineaClasseI e;
        private SkeletroBaseLineaClasseI f;
        private ForseLineaClassA lineaImp;
        // ha a che vedere con diagonale.
        private double h;
        private BitArray i;
        private static int j = 0;
        private static int k = 1;
        private static int l = 2;
        private static int m = 3;
        private static int n = 4;
        private static int o = 7;
        private static bool[] p;
        private List<ClassAa_OssaSkeletro> q;
        private List<ClassAa_OssaSkeletro> r;
        private ClassAa_OssaSkeletro s;
        private int? t;
        private Dictionary<ClassAa_OssaSkeletro.SubClassA, object> u;
        private PuntoDueD v;
        private SkeletroBaseLineaClasseI w;
        private SkeletroBaseLineaClasseI x;
        private double y;
        private ClassAa_OssaSkeletro z;

        static ClassAa_OssaSkeletro()
        {
            bool[] flagArray = new bool[8];
            flagArray[1] = true;
            flagArray[7] = true;
            p = flagArray;
        }

        public ClassAa_OssaSkeletro()
        {
            this.h = double.MaxValue;
            this.i = new BitArray(p);
            this.q = new List<ClassAa_OssaSkeletro>();
            this.r = new List<ClassAa_OssaSkeletro>();
            this.t = null;
            this.y = double.MaxValue;
            this.MethodD(false);
        }

        public ClassAa_OssaSkeletro(PuntoDueD A_0, SkeletroBaseLineaClasseI A_1, SkeletroBaseLineaClasseI A_2)
        {
            this.h = double.MaxValue;
            this.i = new BitArray(p);
            this.q = new List<ClassAa_OssaSkeletro>();
            this.r = new List<ClassAa_OssaSkeletro>();
            this.t = null;
            this.y = double.MaxValue;

            this.MethodA(A_0, A_1, A_2);
        }

        public ClassAa_OssaSkeletro(PuntoDueD A_0, SkeletroBaseLineaClasseI A_1, SkeletroBaseLineaClasseI A_2, bool A_3)
            : this(A_0, A_1, A_2)
        {
            this.MethodF(A_3);
        }

        public ClassAa_OssaSkeletro(PuntoDueD A_0, SkeletroBaseLineaClasseI A_1, SkeletroBaseLineaClasseI A_2, ClassL A_3, ClassAa_OssaSkeletro A_4)
            : this(A_0, A_1, A_2, true)
        {
            this.aa = A_3;
            this.ab = A_4;
        }

        private void MethodA()
        {
            foreach (ClassAa_OssaSkeletro aa in this.r)
            {
                aa.q.Remove(this);
            }
            this.r.Clear();
        }

        public void MethodA(ClassAa_OssaSkeletro A_0)
        {
            this.c = A_0;
        }

        public object MethodA(ClassAa_OssaSkeletro.SubClassA subClass0)
        {
            if (this.u != null)
            {
                object obj2 = null;
                if (this.u.TryGetValue(subClass0, out obj2))
                {
                    return obj2;
                }
            }
            return null;
        }

        private void MethodA(ClassAr A_0)
        {
            foreach (ClassAa_OssaSkeletro aa in A_0.MethodC())
            {
                ClassL item = this.MethodA(aa.MethodW());
                if (item != null)
                {
                    this.ac.Add(item);
                    aa.MethodW().MethodA(item);
                }
            }
        }

        private ClassL MethodA(SkeletroBaseLineaClasseI A_0)
        {
            if (A_0 == this.MethodW())
            {
                return null;
            }
            if (((this.MethodW() == A_0) || (this.MethodC() == A_0)) || ((this.Method().MethodW() == A_0) || (this.MethodN().MethodC() == A_0)))
            {
                return null;
            }
            if (!ClassAtAs.MethodA(A_0, this.MethodJ(), true))
            {
                return null;
            }
            double num = A_0.b.c(this.GetLineaImp().b);
            if ((num >= 0.0) && (num <= 3.1415926535897931))
            {
                return null;
            }
            PuntoDueD puntoDueD = null;
            PuntoDueD x2 = ClassAtAs.MethodB(this.MethodW(), A_0);
            if (x2 != null)
            {
                ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(A_0.b);
                classAt.d();
                classAt.c((double)(classAt.d(this.MethodW().b) / 2.0));
                puntoDueD = ClassAtAs.MethodA(x2, classAt, this.GetLineaImp().a, this.GetLineaImp().b);
            }
            else
            {
                x2 = ClassAtAs.MethodB(this.GetLineaImp(), A_0);
                if (x2 != null)
                {
                    puntoDueD = new PuntoDueD((this.MethodJ().X + x2.X) / 2.0, (this.MethodJ().Y + x2.Y) / 2.0);
                }
            }
            if (puntoDueD == null)
            {
                return null;
            }
            if (!this.MethodS().MethodE().MethodE().d(puntoDueD))
            {
                return null;
            }
            if (!ClassAtAs.MethodA(A_0, puntoDueD, true))
            {
                return null;
            }
            double num2 = ClassAtAs.MethodA((ForseLineaClassA)this.MethodW(), puntoDueD);
            ClassL classL = new ClassL();
            classL.MethodA(this);
            classL.MethodA(A_0);
            classL.MethodA(puntoDueD);
            classL.MethodA(num2);
            classL.MethodC();
            return classL;
        }

        public void MethodA(bool A_0)
        {
            this.i.Set(m, A_0);
        }

        public bool MethodA(double A_0)
        {
            if (this.s == null)
            {
                return false;
            }
            this.MethodB(A_0);
            this.MethodC(A_0);
            if (this.MethodD())
            {
                if (((this.s.aa == this.aa) && (this.s.ab == this.ab)) && this.s.MethodI())
                {
                    if (this.ab.MethodT())
                    {
                        this.s.MethodD(this.ab.MethodH());
                    }
                    return false;
                }
                this.s.MethodA(this.aa.MethodD(), this.MethodC(), this.MethodW());
                if (this.MethodT())
                {
                    this.s.MethodD(this.MethodH());
                    this.s.MethodC(true);
                }
                else if (this.ab.MethodT())
                {
                    this.s.MethodD(this.ab.MethodH());
                }
                this.s.aa = this.aa;
                this.s.ab = this.ab;
                this.s.MethodA();
                this.MethodC(this.s);
                this.s.MethodD(true);
                return true;
            }
            if (this.z != null)
            {
                if ((((this.s.aa == null) && (this.s.ab == null)) && (this.s.MethodI() && (this.s.MethodC() == this.w))) && (this.s.MethodW() == this.x))
                {
                    return false;
                }
                this.s.MethodA(this.v, this.w, this.x);
                if (this.MethodT())
                {
                    this.s.MethodD(this.MethodH());
                    this.s.MethodC(true);
                }
                else if (this.z.MethodT())
                {
                    this.s.MethodD(this.z.MethodH());
                }
                this.s.aa = null;
                this.s.ab = null;
                this.s.MethodA();
                this.MethodC(this.s);
                this.z.MethodC(this.s);
                this.s.MethodD(true);
                return true;
            }
            if (!this.s.MethodI())
            {
                return false;
            }
            this.s.MethodA(this.MethodJ(), this.MethodC(), this.MethodW());
            this.s.MethodD(false);
            return true;
        }

        public ClassAa_OssaSkeletro MethodA(int A_0)
        {
            return this.r[A_0];
        }

        public void MethodA(ClassAa_OssaSkeletro.SubClassA subClass0, object A_1)
        {
            if (this.u == null)
            {
                this.u = new Dictionary<ClassAa_OssaSkeletro.SubClassA, object>();
            }
            this.u[subClass0] = A_1;
        }

        public bool MethodA(ClassL A_0, double A_1)
        {
            if (this.MethodF())
            {
                return false;
            }
            ClassAa_OssaSkeletro classAa = A_0.MethodB();
            A_0.MethodC();
            if ((this.aa == null) || (this.aa.f() >= A_1))
            {
                if (classAa == A_0.MethodB())
                {
                    return false;
                }
                if (this.aa == A_0)
                {
                    return true;
                }
                if ((this.aa != null) && (A_0.f() > this.aa.f()))
                {
                    return false;
                }
            }
            return true;
        }

        private void MethodA(PuntoDueD A_0, SkeletroBaseLineaClasseI A_1, SkeletroBaseLineaClasseI A_2)
        {
            this.d = new PuntoDueD();
            this.d.e(A_0);
            this.e = A_1;
            this.f = A_2;
            this.MethodB(false);
            this.MethodA(false);
            if (ClassAtAs.MethodB(A_1, A_2) == null)
            {
                this.MethodB(true);
                if (((A_1.b.a * A_2.b.a) < 0.0) || ((A_1.b.b * A_2.b.b) < 0.0))
                {
                    this.MethodA(true);
                }
            }
            this.lineaImp = new ForseLineaClassA(A_0, A_2.b);
            if (!this.MethodE())
            {
                ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(A_1.b);
                classAt.d();
                double num = this.lineaImp.b.c(classAt);
                this.lineaImp.b.MethodB((double)(num / 2.0));
            }
            else if (!this.MethodT())
            {
                this.lineaImp.b.MethodB();
            }
            this.h = ClassAtAs.MethodA(this.f, this.d);
            if (this.MethodE())
            {
                this.MethodE(true);
            }
            else
            {
                this.MethodE(this.e.b.c(this.f.b) < 3.1415926535897931);
            }
        }

        public bool MethodAa()
        {
            return ((this.a != null) && (this.a.MethodD() >= 3));
        }

        private void MethodB()
        {
            if (!this.MethodF() && (this.ac == null))
            {
                this.ac = new List<ClassL>();
                ClassAr classAr = this.MethodS();
                PresuntoSkeletroClassAe classAe = classAr.MethodE();
                if (classAe.MethodJ())
                {
                    foreach (ClassAr ar2 in classAe.MethodF())
                    {
                        this.MethodA(ar2);
                    }
                }
                else
                {
                    this.MethodA(classAr);
                }
                this.ac.Sort(SubClassB.a);
            }
        }

        public void MethodB(ClassAa_OssaSkeletro A_0)
        {
            this.b = A_0;
        }

        public void MethodB(ClassAa_OssaSkeletro.SubClassA subClass0)
        {
            if (this.u != null)
            {
                this.u.Remove(subClass0);
            }
        }

        public void MethodB(ClassAr A_0)
        {
            if (this.a != A_0)
            {
                ClassAr a = this.a;
                this.a = A_0;
                if ((this.a == null) && (a != null))
                {
                    this.MethodW().MethodB(this);
                }
                else if ((this.a != null) && (a == null))
                {
                    this.MethodW().MethodC(this);
                }
            }
        }

        public void MethodB(bool A_0)
        {
            this.i.Set(l, A_0);
        }


        //cose a0
        public bool MethodB(double A_0)
        {
            ClassAa_OssaSkeletro z = this.z;
            this.v = null;
            this.w = null;
            this.x = null;
            this.y = double.MaxValue;
            this.z = null;
            ClassAa_OssaSkeletro aa2 = this.MethodN();
            ClassAa_OssaSkeletro aa3 = this.Method();
            if (((aa2 == this) || !aa2.MethodAa()) || (!aa2.MethodF() && !this.MethodF()))
            {
                aa2 = null;
            }
            if (((aa3 == this) || !aa3.MethodAa()) || (!aa3.MethodF() && !this.MethodF()))
            {
                aa3 = null;
            }
            if ((aa2 != null) || (aa3 != null))
            {
                PuntoDueD puntoDueD = (aa2 == null) ? null : ClassAtAs.MethodA(this.GetLineaImp(), aa2.GetLineaImp());
                PuntoDueD x2 = (aa3 == null) ? null : ClassAtAs.MethodA(this.GetLineaImp(), aa3.GetLineaImp());
                double maxValue = (puntoDueD == null) ? double.MaxValue : ClassAtAs.MethodA(this.MethodW(), puntoDueD);
                double num2 = (x2 == null) ? double.MaxValue : ClassAtAs.MethodA(this.MethodW(), x2);
                if (maxValue < (A_0 - ClassAtAs.MethodB()))
                {
                    maxValue = double.MaxValue;
                    puntoDueD = null;
                }
                if (num2 < (A_0 - ClassAtAs.MethodB()))
                {
                    num2 = double.MaxValue;
                    x2 = null;
                }
                if ((puntoDueD == null) && (x2 == null))
                {
                    return (z != this.z);
                }
                if ((this.MethodT() && (puntoDueD != null)) && (x2 != null))
                {
                    double num3 = puntoDueD.MethodC(this.MethodJ());
                    double num4 = x2.MethodC(this.MethodJ());
                    if (num3 <= num4)
                    {
                        this.v = puntoDueD;
                        this.w = aa2.MethodC();
                        this.x = this.MethodW();
                        this.y = maxValue;
                        this.z = aa2;
                    }
                    else
                    {
                        this.v = x2;
                        this.w = this.MethodC();
                        this.x = aa3.MethodW();
                        this.y = num2;
                        this.z = aa3;
                    }
                }
                else if (maxValue < num2)
                {
                    if (puntoDueD != null)
                    {
                        this.v = puntoDueD;
                        this.w = aa2.MethodC();
                        this.x = this.MethodW();
                        this.y = maxValue;
                        this.z = aa2;
                    }
                }
                else if (x2 != null)
                {
                    this.v = x2;
                    this.w = this.MethodC();
                    this.x = aa3.MethodW();
                    this.y = num2;
                    this.z = aa3;
                }
            }
            return (z != this.z);
        }

        public ClassAa_OssaSkeletro MethodB(int A_0)
        {
            return this.q[A_0];
        }

        public SkeletroBaseLineaClasseI MethodC()
        {
            return this.e;
        }

        public void MethodC(ClassAa_OssaSkeletro A_0)
        {
            double num1 = A_0.MethodH() - this.MethodH();
            if (this.q.IndexOf(A_0) == -1)
            {
                this.q.Add(A_0);
            }
            if (A_0.r.IndexOf(this) == -1)
            {
                A_0.r.Add(this);
            }
        }

        public void MethodC(bool A_0)
        {
            this.i.Set(n, A_0);
        }

        public bool MethodC(double A_0)
        {
            ClassAa_OssaSkeletro ab = this.ab;
            this.ab = null;
            this.aa = null;
            this.MethodB();
            if (this.ac == null)
            {
                return false;
            }
            ClassL item = new ClassL();
            item.MethodA((double)(A_0 - ClassAtAs.MethodB()));
            int num = this.ac.BinarySearch(item, ClassAa_OssaSkeletro.SubClassB.a);
            if (num < 0)
            {
                num = ~num;
            }
            this.MethodS().MethodE().MethodJ();
            for (int i = num; i < this.ac.Count; i++)
            {
                ClassL l2 = this.ac[i];
                if ((((this.MethodW() != l2.MethodA()) && (this.MethodC() != l2.MethodA())) && ((this.Method().MethodW() != l2.MethodA()) && (this.MethodN().MethodC() != l2.MethodA()))) && ((l2.f() >= (A_0 - ClassAtAs.MethodB())) && (l2.MethodB() != null)))
                {
                    this.aa = l2;
                    this.ab = l2.MethodB();
                    break;
                }
            }
            return (ab != this.ab);
        }

        public bool MethodD()
        {
            return ((this.aa != null) && (this.aa.f() < this.y));
        }

        public void MethodD(ClassAa_OssaSkeletro A_0)
        {
            this.q.Remove(A_0);
            A_0.r.Remove(this);
        }

        public void MethodD(bool A_0)
        {
            this.i.Set(o, A_0);
        }

        public void MethodD(double A_0)
        {
            this.h = A_0;
        }

        public bool MethodE()
        {
            return this.i.Get(l);
        }

        public void MethodE(ClassAa_OssaSkeletro A_0)
        {
            this.MethodS().MethodB(this, A_0);
        }

        public void MethodE(bool A_0)
        {
            this.i.Set(k, A_0);
        }

        public bool MethodF()
        {
            return this.i.Get(k);
        }

        public void MethodF(ClassAa_OssaSkeletro A_0)
        {
            this.MethodS().MethodA(this, A_0);
        }

        public void MethodF(bool A_0)
        {
            this.i.Set(j, A_0);
        }

        public bool MethodG()
        {
            return this.i.Get(n);
        }

        public override int GetHashCode()
        {
            if (!this.t.HasValue)
            {
                this.t = new int?(Guid.NewGuid().GetHashCode());
            }
            return this.t.Value;
        }

        /// <summary>
        /// Ritorna diagonale 
        /// </summary>
        /// <returns></returns>
        public double MethodH()
        {
            return this.h;
        }

        public bool MethodI()
        {
            return this.i.Get(o);
        }

        public PuntoDueD MethodJ()
        {
            return this.d;
        }

        public ClassAa_OssaSkeletro MethodK()
        {
            if (this.s == null)
            {
                this.MethodB(this.MethodH());
                this.MethodC(this.MethodH());
                if (this.MethodD())
                {
                    this.s = new ClassAa_OssaSkeletro(this.aa.MethodD(), this.MethodC(), this.MethodW(), this.aa, this.ab);
                    if (this.MethodT())
                    {
                        this.s.MethodD(this.MethodH());
                        this.s.MethodC(true);
                    }
                    else if (this.ab.MethodT())
                    {
                        this.s.MethodD(this.ab.MethodH());
                    }
                    this.MethodC(this.s);
                    return this.s;
                }
                if (this.z != null)
                {
                    this.s = new ClassAa_OssaSkeletro(this.v, this.w, this.x, true);
                    if (this.MethodT())
                    {
                        this.s.MethodD(this.MethodH());
                        this.s.MethodC(true);
                    }
                    else if (this.z.MethodT())
                    {
                        this.s.MethodD(this.z.MethodH());
                    }
                    this.MethodC(this.s);
                    this.z.MethodC(this.s);
                    return this.s;
                }
                this.s = new ClassAa_OssaSkeletro(this.MethodJ(), this.MethodC(), this.MethodW());
                this.s.MethodD(false);
            }
            return this.s;
        }

        public IEnumerable<ClassAa_OssaSkeletro> MethodL()
        {
            return this.q;
        }

        public int MethodM()
        {
            return this.r.Count;
        }

        public ClassAa_OssaSkeletro MethodN()
        {
            return this.b;
        }

        public void MethodO()
        {
            this.MethodS().MethodB(this);
        }

        public ClassAa_OssaSkeletro MethodP()
        {
            return this.ab;
        }

        public ForseLineaClassA GetLineaImp()
        {
            return this.lineaImp;
        }

        public ClassL MethodR()
        {
            return this.aa;
        }

        public ClassAr MethodS()
        {
            return this.a;
        }

        public bool MethodT()
        {
            return this.i.Get(m);
        }

        public bool MethodU()
        {
            return this.i.Get(j);
        }

        public void MethodV()
        {
            this.a = null;
            this.ab = null;
            if (this.ac != null)
            {
                this.ac.Clear();
            }
        }

        // Attenzione , questo dovrebbe essere quando richiamo il punto centrale calcolato,
        // quello che avevo intenzione di cambiare.. no!
        public SkeletroBaseLineaClasseI MethodW()
        {
            return this.f;
        }

        public int MethodX()
        {
            return this.q.Count;
        }

        public IEnumerable<ClassAa_OssaSkeletro> methodY()
        {
            return this.r;
        }

        public ClassAa_OssaSkeletro Method()
        {
            return this.c;
        }

        public class SubClassA
        {
            private int a = Guid.NewGuid().GetHashCode();

            public override int GetHashCode()
            {
                return this.a;
            }
        }

        private class SubClassB : IComparer<ClassL>
        {
            public static ClassAa_OssaSkeletro.SubClassB a = new ClassAa_OssaSkeletro.SubClassB();

            public int Compare(ClassL info1, ClassL info2)
            {
                if (info1 != info2)
                {
                    if (info1.f() > info2.f())
                    {
                        return 1;
                    }
                    if (info1.f() < info2.f())
                    {
                        return -1;
                    }
                }
                return 0;
            }
        }
    }
}

